/* This class holds the pool of item templates used to generate all the items
 * in the game.
 */

package item;

import item.defense.DefenseTemplate;
import item.defense.Defense;
import item.engine.EngineTemplate;
import item.engine.Engine;
import item.mod.ModTemplate;
import item.mod.Mod;
import item.ship.ShipTemplate;
import item.ship.Ship;
import item.ship.ShipClass;
import item.weapon.WeaponTemplate;
import item.weapon.Weapon;
import item.weapon.Target;
import status.Status;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public final class ItemPool {

	public static ArrayList<WeaponTemplate> weaponPool;
	public static ArrayList<EngineTemplate> enginePool;
	public static ArrayList<DefenseTemplate> defensePool;
	public static ArrayList<ModTemplate> modPool;
	public static ArrayList<ShipTemplate> shipPool;


	//this blocks sets up the pools and loads all the items
	static{

		weaponPool = new ArrayList<WeaponTemplate>();
		enginePool = new ArrayList<EngineTemplate>();
		defensePool = new ArrayList<DefenseTemplate>();
		modPool = new ArrayList<ModTemplate>();
		shipPool = new ArrayList<ShipTemplate>();
		
		loadShips();
	}//static initialization block


	//loads all the weapon files
	private static void loadWeapons(){
		
		String name = null;
		int minLvl = 0;
		int maxLvl = 0;
		int bprice = 0;
		int lprice = 0;
		int bweight = 0;
		int lweight = 0;
		String sPath = null;
		Rarity rarity = null;
		Status effect = null;
		int bstr = 0;
		int lstr = 0;
		int brstr = 0;
		int lrstr = 0;
		int dur = 0;
		int ldur = 0;
		int bhr = 0;
		int rhr = 0;
		int nshot = 0;
		int nran = 0;
		int xran = 0;
		int rad = 0;
		Target tar = null;
		
		
	}//lead Weapons
	
	
	//loads all the ship files
	private static void loadShips(){

		String name = null;
		int minLvl = 0;
		int maxLvl = 0;
		int bprice = 0;
		int lprice = 0;
		int bweight = 0;
		int lweight = 0;
		String sPath = null;
		Rarity rarity = null;
		int hull = 0;
		int armor = 0;
		int shields = 0;
		int mWep = 0;
		int mDef = 0;
		int mEng = 0;
		int mMod = 0;
		ArrayList<String> weapons;
		ArrayList<String> defenseItems;
		ArrayList<String> engines;
		ArrayList<String> mods;
		ShipClass shipClass = null;
		ArrayList<String> attributes;

		String path = "assets\\items\\ships\\";
		File f = new File(path);
		String[] ships = f.list();

		Scanner fIn = null;		
		
		//reads in all the ship files and makes the ship templates
		for(int i = 0; i < ships.length; i++){

			weapons = new ArrayList<String>();
			defenseItems = new ArrayList<String>();
			engines = new ArrayList<String>();
			mods = new ArrayList<String>();
			attributes = new ArrayList<String>();

			if(!ships[i].equals("readme_ship.txt")){

				try {

					fIn = new Scanner(new File(path + ships[i]));
				} catch (FileNotFoundException e) {

					System.out.println("Problem with reading in files. @1");
				}//try catch FileNotFoundException

				name = fIn.nextLine();

				String level = fIn.nextLine();

				minLvl = Integer.parseInt(
						level.substring(0, level.indexOf('-')));
				maxLvl = Integer.parseInt(
						level.substring(level.indexOf('-') + 1));

				bprice = fIn.nextInt();
				lprice = fIn.nextInt();
				bweight = fIn.nextInt();
				lweight = fIn.nextInt();
				fIn.nextLine();					
				
				sPath = fIn.nextLine();

				rarity = Rarity.valueOf(fIn.nextLine().toUpperCase());

				hull = fIn.nextInt();
				armor = fIn.nextInt();
				shields = fIn.nextInt();
				mWep = fIn.nextInt();
				mDef = fIn.nextInt();
				mEng = fIn.nextInt();
				mMod = fIn.nextInt();
				fIn.nextLine();
				
				shipClass = ShipClass.valueOf(fIn.nextLine().toUpperCase());

				String s;

				s = fIn.nextLine();

				if(s.length() > 0){

					while(s.indexOf('|') != -1){

						attributes.add(s.substring(0, s.indexOf('|')));
						s = s.substring(s.indexOf('|') + 1);
					}//while

					attributes.add(s);
				}//if

				while(!(s = fIn.nextLine()).equals("EOF")){

					switch(s.charAt(0)){

					case 'W':
						weapons.add(s);
						break;

					case 'D':
						defenseItems.add(s);
						break;

					case 'E':
						engines.add(s);
						break;

					case 'M':
						mods.add(s);
						break;
					}//switch
				}//while


				
				
				shipPool.add(new ShipTemplate(name, minLvl, maxLvl, bprice,
						lprice,	bweight, lweight, sPath, rarity, hull, armor,
						shields, mWep, mDef, mEng, mMod, weapons, defenseItems,
						engines, mods, shipClass, attributes));
			}//if
		}//for
	}//loadShips


	//returns the ship with name n and of level l
	//returns null if the weapon doesn't exist or it cannot be level l
	public static Ship getShip(String n, int l){

		return null;
	}//getShip(String, int)


	//returns a random ship of lvl l taking rarity and attributes into account
	//if attributes is null then the item cannot require any attributes
	public static Ship getShip(int l, ArrayList<String> attributes){

		return null;
	}//getShip(int, ArrayList<String>)

	//returns the weapon with string n and of level l
	//returns null if the weapon doesn't exist or it cannot be level l
	public static Weapon getWeapon(String n, int l){

		return null;
	}//getWeapon (String, int)


	//returns a random weapon of level l taking rarity and attributes into 
	//account if attributes is null then the item cannot require any attributes
	public static Weapon getWeapon(int l, ArrayList<String> attributes){

		return null;
	}//getWeapon (int, ArrayList<String>)


	//returns the defensive item with string n and of level l
	//returns null if the defensive item doesn't exist or it cannot be level l
	public static Defense getDefense(String n, int l){

		return null;
	}//getDefense(String, int)


	//returns a random defensive item of level l taking rarity and attributes
	//into account if attributes is null then the item cannot require any 
	//attributes
	public static Defense getDefense(int l, ArrayList<String> attributes){

		return null;
	}//getdefensive item (int, ArrayList<String>)


	//returns the engine with string n and of level l
	//returns null if the engine doesn't exist or it cannot be level l
	public static Engine getEngine(String n, int l){

		return null;
	}//getEngine (String, int)


	//returns a random engine of level l taking rarity and attributes into 
	//account if attributes is null then the item cannot require any attributes
	public static Engine getEngine(int l, ArrayList<String> attributes){

		return null;
	}//getEngine (int, ArrayList<String>)


	//returns the mod with string n and of level l
	//returns null if the mod doesn't exist or it cannot be level l
	public static Mod getMod(String n, int l){

		return null;
	}//getMod (String, int)


	//returns a random mod of level l taking rarity and attributes into account
	//if attributes is null then the item cannot require any attributes
	public static Mod getMod(int l, ArrayList<String> attributes){

		return null;
	}//getMod (int, ArrayList<String>)
}//ItemPool